Skip to content

fix: add file-size guard to prevent memory spikes from oversized files (APP-4519)#11410

Closed
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
fix/memory-large-file-guard-global-buffer-model
Closed

fix: add file-size guard to prevent memory spikes from oversized files (APP-4519)#11410
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
fix/memory-large-file-guard-global-buffer-model

Conversation

@warp-dev-github-integration
Copy link
Copy Markdown

Description

Add a 50 MiB file-size guard to prevent memory spikes when opening oversized files in the editor.

Root cause: GlobalBufferModel::populate_buffer_with_read_content loaded arbitrarily large file content into Buffer::replace_all, triggering multi-gigabyte SumTree<BufferText>::append_str allocations and SyntaxTreeState::parse_text tree-sitter parsing. The pprof heap profile from the Sentry event showed 8.07 GB (75.94%) through the Buffer path and 2.41 GB (22.73%) through tree-sitter, for a total footprint of ~20 GiB.

Fix: There were no file-size guards anywhere in the file loading pipeline. This PR adds layered protection:

  1. FileLoadError::FileTooLarge — new error variant with path, size, and limit fields
  2. MAX_EDITOR_FILE_SIZE (50 MiB) — constant in warp_files, generous for source code
  3. FileModel::open() — checks file size before read_to_string (initial load)
  4. FileModel::read_content_for_file() — checks size (used by discard/reload)
  5. FileModel::reload_file_paths() — skips oversized files during auto-reload
  6. GlobalBufferModel::populate_buffer_with_read_content() — safety-net content-length guard
  7. GlobalBufferModel::apply_open_buffer_response() — guards remote buffer content
  8. Binary file reader — handles new FileTooLarge variant in match

Linked Issue

Testing

  • Verified the code compiles with cargo check --package warp --lib

  • Verified cargo fmt and cargo clippy pass with no warnings

  • The fix is defensive and minimal: each guard early-returns with FailedToLoad which the existing UI already handles

  • I have manually tested my changes locally with ./script/run

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

Conversation: https://staging.warp.dev/conversation/9d0a6926-1b89-4d3b-a3ea-109d18764f73
Run: https://oz.staging.warp.dev/runs/019e45a6-a645-7d9b-9c8c-e72d1160d1f7

This PR was generated with Oz.

APP-4519)

Add a 50 MiB file-size limit to the editor buffer loading pipeline to
prevent multi-gigabyte memory spikes caused by loading very large files
into SumTree buffers and tree-sitter parsers.

Root cause: GlobalBufferModel::populate_buffer_with_read_content loaded
arbitrarily large file content into Buffer::replace_all, which triggers
SumTree<BufferText>::append_str allocations and SyntaxTreeState::parse_text.
The pprof heap profile showed 8.07 GB through Buffer::replace_all and
2.41 GB through tree-sitter parsing for a single file.

Changes:
- Add FileLoadError::FileTooLarge variant with path, size, and limit fields
- Add MAX_EDITOR_FILE_SIZE (50 MiB) constant in warp_files
- FileModel::open(): check file size before read_to_string
- FileModel::read_content_for_file(): check file size (used by discard)
- FileModel::reload_file_paths(): skip oversized files during auto-reload
- GlobalBufferModel::populate_buffer_with_read_content(): safety-net guard
- GlobalBufferModel::apply_open_buffer_response(): guard remote buffers
- Handle new FileTooLarge variant in read_binary_file_context match

Sentry: https://sentry.io/organizations/warpdotdev/issues/7259255054/events/ddc1194e8a7f40a595f65a9b2378740b/

Co-Authored-By: Oz <oz-agent@warp.dev>
@kevinchevalier
Copy link
Copy Markdown
Contributor

Closing as duplicate of #12125 — both add a 50 MB FileTooLarge file size guard in FileModel::open. Keeping the newest PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants